<?php
/**
 * 404 Error Page Template
 * 404错误页面模板，基于HTML模板 404.html
 * 
 * @package WP Bootstrap Woo
 */

defined('ABSPATH') || exit;

get_header(); ?>

<!-- 404 error page start -->
<section class="error-page">
    <div class="container">
        <div class="error-page-area">
            <div class="row justify-content-center">
                <div class="col-12 col-lg-8 col-md-10">
                    <div class="error-content">
                        
                        <!-- 404 illustration -->
                        <div class="error-illustration">
                            <div class="error-number">
                                <span class="number">4</span>
                                <div class="zero-container">
                                    <div class="zero">
                                        <span>0</span>
                                        <div class="zero-decoration">
                                            <i class="feather-search"></i>
                                        </div>
                                    </div>
                                </div>
                                <span class="number">4</span>
                            </div>
                        </div>
                        
                        <!-- error message -->
                        <div class="error-message">
                            <h1>Oops! Page Not Found</h1>
                            <p>The page you're looking for doesn't exist or has been moved. Don't worry, it happens to the best of us!</p>
                        </div>
                        
                        <!-- search form -->
                        <div class="error-search">
                            <div class="search-form-wrap">
                                <form role="search" method="get" action="<?php echo esc_url(home_url('/')); ?>" class="search-form">
                                    <div class="search-input-group">
                                        <input type="search" name="s" placeholder="Search for products, pages, or anything..." value="<?php echo get_search_query(); ?>" class="search-input" required>
                                        <button type="submit" class="search-btn">
                                            <i class="feather-search"></i>
                                            <span>Search</span>
                                        </button>
                                    </div>
                                </form>
                            </div>
                        </div>
                        
                        <!-- helpful links -->
                        <div class="helpful-links">
                            <h5>Try these helpful links:</h5>
                            <div class="link-grid">
                                <a href="<?php echo esc_url(home_url('/')); ?>" class="help-link">
                                    <div class="link-icon">
                                        <i class="feather-home"></i>
                                    </div>
                                    <div class="link-content">
                                        <h6>Homepage</h6>
                                        <p>Go back to our homepage</p>
                                    </div>
                                </a>
                                
                                <?php if (class_exists('WooCommerce')) : ?>
                                <a href="<?php echo wc_get_page_permalink('shop'); ?>" class="help-link">
                                    <div class="link-icon">
                                        <i class="feather-shopping-bag"></i>
                                    </div>
                                    <div class="link-content">
                                        <h6>Shop</h6>
                                        <p>Browse our products</p>
                                    </div>
                                </a>
                                <?php endif; ?>
                                
                                <a href="<?php echo get_permalink(get_option('page_for_posts')); ?>" class="help-link">
                                    <div class="link-icon">
                                        <i class="feather-book-open"></i>
                                    </div>
                                    <div class="link-content">
                                        <h6>Blog</h6>
                                        <p>Read our latest articles</p>
                                    </div>
                                </a>
                                
                                <a href="#" class="help-link" onclick="window.history.back(); return false;">
                                    <div class="link-icon">
                                        <i class="feather-arrow-left"></i>
                                    </div>
                                    <div class="link-content">
                                        <h6>Go Back</h6>
                                        <p>Return to previous page</p>
                                    </div>
                                </a>
                            </div>
                        </div>
                        
                        <!-- popular products -->
                        <?php if (class_exists('WooCommerce')) : ?>
                        <div class="popular-products">
                            <h5>Popular Products</h5>
                            <div class="products-grid">
                                <?php
                                $popular_products = wc_get_products(array(
                                    'limit' => 4,
                                    'orderby' => 'popularity',
                                    'status' => 'publish',
                                    'visibility' => 'catalog'
                                ));
                                
                                if ($popular_products) :
                                    foreach ($popular_products as $product) :
                                        $product_id = $product->get_id();
                                        $product_name = $product->get_name();
                                        $product_price = $product->get_price_html();
                                        $product_link = get_permalink($product_id);
                                        $product_image = $product->get_image(array(120, 120));
                                        ?>
                                        <div class="product-card">
                                            <a href="<?php echo esc_url($product_link); ?>" class="product-link">
                                                <div class="product-image">
                                                    <?php echo $product_image; ?>
                                                </div>
                                                <div class="product-info">
                                                    <h6><?php echo esc_html($product_name); ?></h6>
                                                    <div class="product-price"><?php echo $product_price; ?></div>
                                                </div>
                                            </a>
                                        </div>
                                        <?php
                                    endforeach;
                                endif;
                                ?>
                            </div>
                        </div>
                        <?php endif; ?>
                        
                        <!-- contact support -->
                        <div class="contact-support">
                            <div class="support-card">
                                <div class="support-icon">
                                    <i class="feather-headphones"></i>
                                </div>
                                <div class="support-content">
                                    <h6>Need Help?</h6>
                                    <p>Can't find what you're looking for? Our support team is here to help.</p>
                                    <a href="#" class="btn-contact">Contact Support</a>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</section>
<!-- 404 error page end -->

<style>
.error-page {
    padding: 80px 0;
    background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
    min-height: 70vh;
}

.error-page-area {
    text-align: center;
}

.error-content {
    background: #fff;
    border-radius: 20px;
    padding: 60px 40px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.1);
    margin-bottom: 40px;
}

.error-illustration {
    margin-bottom: 40px;
}

.error-number {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 20px;
    margin-bottom: 30px;
}

.number {
    font-size: 120px;
    font-weight: 900;
    color: #007cba;
    line-height: 1;
    text-shadow: 0 4px 8px rgba(0,0,0,0.1);
}

.zero-container {
    position: relative;
}

.zero {
    font-size: 120px;
    font-weight: 900;
    color: #dee2e6;
    line-height: 1;
    position: relative;
}

.zero-decoration {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 24px;
    color: #6c757d;
    animation: float 3s ease-in-out infinite;
}

@keyframes float {
    0%, 100% { transform: translate(-50%, -50%) translateY(0); }
    50% { transform: translate(-50%, -50%) translateY(-10px); }
}

.error-message h1 {
    font-size: 36px;
    font-weight: 700;
    color: #212529;
    margin-bottom: 15px;
}

.error-message p {
    font-size: 18px;
    color: #6c757d;
    margin-bottom: 40px;
    max-width: 500px;
    margin-left: auto;
    margin-right: auto;
    line-height: 1.6;
}

.error-search {
    margin-bottom: 50px;
}

.search-input-group {
    display: flex;
    max-width: 500px;
    margin: 0 auto;
    background: #f8f9fa;
    border-radius: 12px;
    padding: 8px;
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.1);
}

.search-input {
    flex: 1;
    border: none;
    background: transparent;
    padding: 15px 20px;
    font-size: 16px;
    color: #495057;
}

.search-input:focus {
    outline: none;
}

.search-input::placeholder {
    color: #adb5bd;
}

.search-btn {
    background: #007cba;
    color: #fff;
    border: none;
    padding: 15px 25px;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
    transition: background 0.3s ease;
    display: flex;
    align-items: center;
    gap: 8px;
}

.search-btn:hover {
    background: #005a8b;
}

.helpful-links {
    margin-bottom: 50px;
}

.helpful-links h5 {
    margin-bottom: 30px;
    color: #495057;
    font-weight: 600;
}

.link-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
    max-width: 800px;
    margin: 0 auto;
}

.help-link {
    display: block;
    background: #f8f9fa;
    border-radius: 12px;
    padding: 25px 20px;
    text-decoration: none;
    transition: all 0.3s ease;
    border: 2px solid transparent;
}

.help-link:hover {
    background: #fff;
    border-color: #007cba;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

.link-icon {
    font-size: 24px;
    color: #007cba;
    margin-bottom: 15px;
}

.link-content h6 {
    margin-bottom: 5px;
    color: #212529;
    font-weight: 600;
}

.link-content p {
    margin: 0;
    color: #6c757d;
    font-size: 14px;
}

.popular-products {
    margin-bottom: 50px;
}

.popular-products h5 {
    margin-bottom: 30px;
    color: #495057;
    font-weight: 600;
}

.products-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 20px;
    max-width: 600px;
    margin: 0 auto;
}

.product-card {
    background: #f8f9fa;
    border-radius: 12px;
    overflow: hidden;
    transition: transform 0.3s ease;
}

.product-card:hover {
    transform: translateY(-2px);
}

.product-link {
    display: block;
    text-decoration: none;
    color: inherit;
}

.product-image {
    aspect-ratio: 1;
    overflow: hidden;
    background: #fff;
}

.product-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.product-info {
    padding: 15px;
}

.product-info h6 {
    margin-bottom: 8px;
    color: #212529;
    font-weight: 500;
    font-size: 14px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.product-price {
    color: #007cba;
    font-weight: 600;
    font-size: 14px;
}

.contact-support {
    margin-bottom: 0;
}

.support-card {
    background: linear-gradient(135deg, #007cba 0%, #005a8b 100%);
    border-radius: 12px;
    padding: 30px;
    color: #fff;
    max-width: 400px;
    margin: 0 auto;
}

.support-icon {
    font-size: 32px;
    margin-bottom: 20px;
}

.support-content h6 {
    margin-bottom: 10px;
    font-weight: 600;
    font-size: 18px;
}

.support-content p {
    margin-bottom: 25px;
    opacity: 0.9;
    line-height: 1.5;
}

.btn-contact {
    background: rgba(255,255,255,0.2);
    color: #fff;
    padding: 12px 25px;
    border-radius: 8px;
    text-decoration: none;
    font-weight: 600;
    transition: background 0.3s ease;
    display: inline-block;
}

.btn-contact:hover {
    background: rgba(255,255,255,0.3);
    color: #fff;
}

@media (max-width: 768px) {
    .error-content {
        padding: 40px 20px;
        margin: 20px;
    }
    
    .error-number {
        gap: 10px;
    }
    
    .number,
    .zero {
        font-size: 80px;
    }
    
    .error-message h1 {
        font-size: 28px;
    }
    
    .error-message p {
        font-size: 16px;
    }
    
    .search-input-group {
        flex-direction: column;
        gap: 10px;
    }
    
    .link-grid {
        grid-template-columns: 1fr;
    }
    
    .products-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 480px) {
    .number,
    .zero {
        font-size: 60px;
    }
    
    .products-grid {
        grid-template-columns: 1fr;
    }
}
</style>

<script>
document.addEventListener('DOMContentLoaded', function() {
    // Add some interactive animations
    const errorNumber = document.querySelector('.error-number');
    
    if (errorNumber) {
        errorNumber.addEventListener('mouseenter', function() {
            this.style.transform = 'scale(1.05)';
        });
        
        errorNumber.addEventListener('mouseleave', function() {
            this.style.transform = 'scale(1)';
        });
    }
    
    // Search form enhancements
    const searchForm = document.querySelector('.search-form');
    const searchInput = document.querySelector('.search-input');
    
    if (searchForm && searchInput) {
        searchInput.addEventListener('keypress', function(e) {
            if (e.key === 'Enter') {
                e.preventDefault();
                if (this.value.trim()) {
                    searchForm.submit();
                }
            }
        });
    }
});
</script>

<?php get_footer(); ?>